package com.qububu.play.common.dto;

import java.io.Serializable;
import java.util.Arrays;

import com.qububu.play.common.dto.ArticleInfoDto.ArticleType;
import com.qububu.utils.DateUtil;
import com.qububu.utils.SystemUtil;


public class ArticleDetailMsgDto implements Serializable{
	
	private static final long serialVersionUID = 1L;
	private String msgId;
	private String msgTitle;
	private String msgContent;
	private String msgCreateIp;
	private int msgCreateDttm;
	private ArticleTypeMsg msgTypeMsg;
	private String articleId;
	private String parentMsgId;
	private ArticleAuthor author;
	
	/**
	 *  得到加密的articleId, userId
	 */
	public ArticleDetailMsgDto(String msgId, String articleId, String parentMsgId){
		this.msgId = msgId;
		this.articleId = articleId;
		this.parentMsgId = parentMsgId;
	}
	
	/**
	 *  得到未加密的articleId, userId
	 */
	public ArticleDetailMsgDto(long msgId, long articleId, long parentMsgId){
		this.msgId = SystemUtil.encrypt(String.valueOf(msgId));
		this.articleId = SystemUtil.encrypt(String.valueOf(articleId));
		this.parentMsgId = SystemUtil.encrypt(String.valueOf(parentMsgId));
	}

	public ArticleAuthor getAuthor() {
		return author;
	}

	public void setAuthor(ArticleAuthor author) {
		this.author = author;
	}
	
	public String getMsgTitle() {
		return msgTitle;
	}

	public void setMsgTitle(String msgTitle) {
		this.msgTitle = msgTitle;
	}

	public String getMsgContent() {
		return msgContent;
	}

	public void setMsgContent(String msgContent) {
		this.msgContent = msgContent;
	}

	public String getMsgCreateIp() {
		return msgCreateIp;
	}

	public void setMsgCreateIp(String msgCreateIp) {
		this.msgCreateIp = msgCreateIp;
	}

	public int getMsgCreateDttm() {
		return msgCreateDttm;
	}

	public void setMsgCreateDttm(int msgCreateDttm) {
		this.msgCreateDttm = msgCreateDttm;
	}

	public ArticleTypeMsg getMsgTypeMsg() {
		return msgTypeMsg;
	}

	public void setArticleTypeMsg(ArticleTypeMsg msgTypeMsg) {
		this.msgTypeMsg = msgTypeMsg;
	}

	public String getMsgId() {
		return msgId;
	}

	public String getArticleId() {
		return articleId;
	}

	public String getParentMsgId() {
		return parentMsgId;
	}
	
	public String showTimeToDT() {
		return DateUtil.formatDTString(msgCreateDttm);
	}


	public enum ArticleTypeMsg {
		SPORT(0),
		DINE(1),
		BLAST(2),//吐槽
		SHOW(3);
		
		private int intValue;
		
		private ArticleTypeMsg (int intValue) {
			this.intValue = intValue;
		}
		/**
		 * 返回int值类型。
		 * @return
		 */
		public int toIntValue() {
			return intValue;
		}
		
		
		/**
		 * 根据传入字符串来返回对应的状态类型
		 */
		public static ArticleTypeMsg getArticleType (String strValue){
			
			try {
				ArticleTypeMsg type = valueOf(strValue);
				return type;
			} catch (Exception e) {
				throw new IllegalArgumentException("Value '" + strValue + "' is not allowed in ArticleType. Only "
						+ Arrays.toString(ArticleType.values()) + " are allowed."
						);
			}
		}
		
		/**
		 * 根据传入INT值来返回对应的状态类型
		 */
		public static ArticleTypeMsg getArticleTypeMsg (int intValue){
			
			for (ArticleTypeMsg elem : ArticleTypeMsg.values()) {
				if (elem.toIntValue() == intValue) {
					return elem;
				}
			}
			throw new IllegalArgumentException("Value '" + intValue
					+ "' is not allowed in ArticleType.");
		}
		
	}
}

